<template>
  <div class="index-box" ref="index">
      <p class="title">门店公告信息</p>
      <el-form label-position="right" :model="form" :rules="formRules" ref="form">
        <el-form-item label="公告主题:" prop="title" label-width="125px"  style="width:100%" >
            <el-input v-model="form.title" placeholder="请输入公告主题" clearable />
        </el-form-item>
        <el-form-item label="公告详情:" prop="content" label-width="125px" class="textarea">
        	<el-input v-model="form.content" placeholder="请输入公告主题" clearable type="textarea" rows="8" maxlength="200" show-word-limit/>
           <!--<quill-editor v-model="form.content" ref="myQuillEditor" style="height:400px"></quill-editor>-->
        </el-form-item>
        <el-form-item label-width="125px" style="padding-top:10px">
           <el-button @click="resetForm('form')" >重 置</el-button>
           <el-button type="primary" @click="submitForm('form')"  :loading="userLoading">保 存</el-button>
        </el-form-item>
      </el-form>
  </div>
</template>

<script>
  import common from '@/api/api';
  import {addOrUpdate,getAnnouncement} from '@/api/getData'
  import option from '../../common/option.js';
  import { quillEditor } from "vue-quill-editor"; //调用编辑器
  import 'quill/dist/quill.core.css';
  import 'quill/dist/quill.snow.css';
  import 'quill/dist/quill.bubble.css';

  export default {
    data() {
      return {
        loading: false,
        userLoading:false,
        form:{
          title:'',
          content:'',
        },
        formRules:{
          title: [{ required: true, message: "请输入公告主题", trigger: "blur" }],
          content: [{ required: true, message: "请输入公告详情", trigger: "blur" }]
        }

      }
    },
    components: {
      quillEditor
    },
    computed: {
      pickerOptions: () => {
        return option.pickerOptions;
      }
    },
    mounted() {
      this.getSelect();
    },
    methods: {
      getSelect(){
        getAnnouncement().then((result) => {
          this.form.title = result.data.title;
          this.form.content = result.data.content;
        });
      },
      submitForm(formName){/*申请好店推广位 提交*/
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.userLoading = true;
            addOrUpdate(this.form).then((result) => {
              if (result.code == 200) {
                this.$message.success(result.msg);
              } else {
                this.$message.error(result.msg);
              }
              this.userLoading = false;
            });
          }
        })
      },


    }
  }
</script>

<style scoped lang="scss">
  .textarea /deep/ .el-form-item__content{
    height:100%;
  }
  .title{
    text-align: center;
    font-size: 16px;
    font-weight: bold;
  }
</style>
